﻿using System;
using System.Collections;
using UnityEngine;

namespace UniRx.Examples
{
	// Token: 0x020001E9 RID: 489
	public class Sample05_ConvertFromCoroutine
	{
		// Token: 0x06000A3D RID: 2621 RVA: 0x00036EA8 File Offset: 0x000352A8
		public static IObservable<string> GetWWW(string url)
		{
			return Observable.FromCoroutine<string>((IObserver<string> observer, CancellationToken cancellationToken) => Sample05_ConvertFromCoroutine.GetWWWCore(url, observer, cancellationToken));
		}

		// Token: 0x06000A3E RID: 2622 RVA: 0x00036ED4 File Offset: 0x000352D4
		private static IEnumerator GetWWWCore(string url, IObserver<string> observer, CancellationToken cancellationToken)
		{
			WWW www = new WWW(url);
			while (!www.isDone && !cancellationToken.IsCancellationRequested)
			{
				yield return null;
			}
			if (cancellationToken.IsCancellationRequested)
			{
				yield break;
			}
			if (www.error != null)
			{
				observer.OnError(new Exception(www.error));
			}
			else
			{
				observer.OnNext(www.text);
				observer.OnCompleted();
			}
			yield break;
		}
	}
}
